<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="110px">
      <el-form-item label="缴费状态" prop="patientId">
<!--        <el-input
          v-model="queryParams.patientId"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />-->
        <el-select
          v-model="pId"
          placeholder="请选择"
          @change="ddddd(pId)"
        >
          <el-option
            v-for="item in statusList"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="身份证号码查询" prop="dischargeStatus">
        <el-input
          v-model="queryParams.dischargeStatus"
          placeholder="请输入身份证号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="${comment}" prop="dischargeTime">
        <el-date-picker clearable
          v-model="queryParams.dischargeTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="${comment}" prop="dischargePrice">
        <el-input
          v-model="queryParams.dischargePrice"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="hosptilpriceTypeid">
        <el-input
          v-model="queryParams.hosptilpriceTypeid"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['hospital:discharge:add']"
        >新增</el-button>
      </el-col>-->
<!--      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['hospital:discharge:edit']"
        >修改</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-user"
          size="small"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['hospital:discharge:remove']"
        >缴费</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="small"
          @click="handleExport"
          v-hasPermi="['hospital:discharge:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dischargeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="dischargeId" v-if="false"/>
      <el-table-column label="病人姓名" align="center" prop="patientName" />
      <el-table-column label="费用类型" align="center" prop="hosptilpriceTypename" />
      <el-table-column label="费用(元)" align="center" prop="dischargePrice" />
      <el-table-column label="缴费状态" align="center" prop="dischargeStatus" />
      <el-table-column label="缴费时间" align="center" prop="dischargeTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dischargeTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
<!--          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="addshow = true"
            v-hasPermi="['hospital:discharge:edit']"
          >修改</el-button>-->
          <el-button
            size="small"
            icon="el-icon-user"
            type="primary"
            @click="handleDelete(scope.row)"
            v-hasPermi="['hospital:discharge:remove']"
          >缴费</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改出院费用总计对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="${comment}" prop="dischargeStatus">
          <el-input v-model="form.dischargeStatus" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="dischargeTime">
          <el-date-picker clearable
            v-model="form.dischargeTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="dischargePrice">
          <el-input v-model="form.dischargePrice" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="hosptilpriceTypeid">
          <el-input v-model="form.hosptilpriceTypeid" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="patientId">
          <el-input v-model="form.patientId" placeholder="请输入${comment}" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- ---------------------缴费------------------- -->
    <el-dialog title="缴费页面" :visible.sync="addshow" width="15%">
      <div class="demo-image__placeholder">
        <div class="block" align="center">
          <span class="demonstration"><font size="3" color="black">请缴费{{allCost}}元</font></span>
          <el-image :src="src"></el-image>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="addshow = false">取消支付</el-button>
        <el-button type="primary" @click="finish">已完成支付</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listDischarge, getDischarge, delDischarge, delDischarge2 ,addDischarge, updateDischarge } from "@/api/hospital/discharge";

export default {
  name: "Discharge",
  data() {
    return {
      pId: "",
      statusList:[
        {
          value: 1,
          label:"未缴费"
        },
        {
          value: 2,
          label:"已缴费"
        }
      ],
      temp: "",
      src: 'https://img1.baidu.com/it/u=1543744943,230774498&fm=253&fmt=auto&app=138&f=GIF?w=200&h=200',
      addshow: false,
      allCost: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 出院费用总计表格数据
      dischargeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dischargeStatus: null,
        dischargeTime: null,
        dischargePrice: null,
        hosptilpriceTypeid: null,
        patientId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    ddddd(pId){
      alert(pId);
      this.queryParams.hosptilpriceTypeid = pId;
      this.handleQuery();
    },
    /** 查询出院费用总计列表 */
    getList() {
      this.loading = true;
      listDischarge(this.queryParams).then(response => {
        this.dischargeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        dischargeId: null,
        dischargeStatus: null,
        dischargeTime: null,
        dischargePrice: null,
        hosptilpriceTypeid: null,
        patientId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.hosptilpriceTypeid = null;
      this.pId = "";
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.dischargeId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加出院费用总计";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const dischargeId = row.dischargeId || this.ids
      getDischarge(dischargeId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改出院费用总计";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.dischargeId != null) {
            updateDischarge(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDischarge(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    finish(){
      delDischarge2(this.temp).then(response => {
        this.addshow = false;
        this.getList();
        this.$modal.msgSuccess("缴费成功");
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const dischargeIds = row.dischargeId || this.ids;
      this.temp = dischargeIds;
      delDischarge(dischargeIds).then(response => {
        this.allCost = response.data.allCost;
        alert(this.allCost);
        this.addshow = true;
        //this.$modal.msgSuccess("缴费成功");
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('hospital/discharge/export', {
        ...this.queryParams
      }, `discharge_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
